package org.smartagents.util;

import java.awt.*;


public class Utils {
    public static final int MAX_COLOR_STEPS = 5;

    public static Color calculateColor(String code) {

        float r = 0.1f;
        float g = 0.1f;
        float b = 0.1f;

        int reds = 1;
        int greens = 1;
        int blues = 1;

        for (int j = 0; j < code.length(); j++) {
            char i = code.charAt(j);
            if (i < 80) {
                r += i;
                reds++;
            } else if (i >= 80 && i < 166) {
                g += i;
                greens++;
            } else {
                b += i;
                blues++;
            }
        }
        System.out.println("");

        if (reds > 0) r = r / reds / 128;
        if (greens > 0) g = g / greens / 128;
        if (blues > 0) b = b / blues / 128;

        System.out.println(code+ " " + r + "("+reds+") "+ g+"("+greens+") "+ b+"("+blues+")");

        r /= (reds< MAX_COLOR_STEPS ? reds:1);
        g /= (greens< MAX_COLOR_STEPS ? greens:1);
        b /= (blues< MAX_COLOR_STEPS ? blues:1);

        return new Color(r, g, b);
    }

}
